//
//  HomeCollectionViewCell.m
//  网易新闻
//
//  Created by 王宇先 on 16/4/9.
//  Copyright © 2016年 王宇先. All rights reserved.
//

#import "HomeCollectionViewCell.h"
#import "HomePageTableViewCell.h"
#import "HomePageModel.h"
#import "TableView.h"
@interface HomeCollectionViewCell ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain)TableView *tableview;

@end
@implementation HomeCollectionViewCell
#pragma mark - init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self creatTableView];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    self.tableview.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 64);
}
- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    return layoutAttributes;
}
- (void)layoutSubviews{
    
    [super layoutSubviews];
}
#pragma mark - 创建 TableView
- (void)creatTableView{
    
    self.tableview = [[TableView alloc]init];
    [self.contentView addSubview:self.tableview];
    self.tableview.dataSource = self;
    self.tableview.delegate = self;
    
    UINib *nib = [UINib nibWithNibName:@"HomePageTableViewCell" bundle:[NSBundle mainBundle]];
    [self.tableview registerNib:nib forCellReuseIdentifier:@"poolOfHomePage"];
    self.tableview.allowsSelection = NO;
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arrOfmodel1.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 150;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HomePageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"poolOfHomePage"];
    HomePageModel *model1 = [self.arrOfmodel1 objectAtIndex:indexPath.row];
    [cell setCellvalue:model1];
    return cell;
}
//重写setter方法:
- (void)setArrOfmodel1:(NSMutableArray *)arrOfmodel1
{
    if (_arrOfmodel1 != arrOfmodel1) {
        
    }
    //刷新tableView;
    [self.tableview reloadData];
}
@end
